package demo5;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: liangyuanzhang
 * Date: 2025-2-28
 * Time: 8:28
 */
class OutClass {

    public int data1 = 1;
    private int data2 = 2;
    public static int data3 = 3;

    //静态内部类
    static class InnerClass {
        public int data4 = 4;
        private int data5 = 5;
        public static  int data6 = 6;

        public void test() {
            OutClass outClass = new OutClass();
            System.out.println(outClass.data1);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
            System.out.println("test方法执行了....");
        }
    }

}


class OutClass2 {

    public int data1 = 1;
    private int data2 = 2;
    public static int data3 = 3;

    //内部类
    class InnerClass2 {

        public int data1 = 1000;

        public int data4 = 4;

        private int data5 = 5;

        public static  int data6 = 6;

        public void test() {
            OutClass2 outClass2 = new OutClass2();
            System.out.println(outClass2.data1);
            System.out.println(OutClass2.this.data1);
            System.out.println(this.data1);
            System.out.println(data2);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
            System.out.println("test()方法执行了......");
        }
    }

}

class Out {
    public void test1() {
        System.out.println("haha");
    }
}

interface IA {
    void test1();
}


public class Test {

    public static void main(String[] args) {
        //这个类 实现了 IA 接口 并且同时重写了test1这个方法
        IA a = new IA(){
            @Override
            public void test1() {
                System.out.println("hahahhaha");
            }
        };
        a.test1();

        /*new Out(){

        }.test1();*/
        /*new Out(){
            @Override
            public void test1() {
                System.out.println("heihei");
            }
        }.test1();*/
    }

    public void testMethod() {
        //局部内部类
        class Inner {
            public int data1;

            public void func() {
                System.out.println("func");
            }
        }

        Inner inner = new Inner();
        inner.func();
    }


    public static void main11(String[] args) {
        //如何实例化一个实例内部类对象
        //InnerClass2 innerClass2 = new InnerClass2();
        OutClass2 outClass2 = new OutClass2();

        OutClass2.InnerClass2 innerClass = outClass2.new InnerClass2();
        innerClass.test();
    }
    public static void main1(String[] args) {
        //如何实例化一个静态内部类对象
        //InnerClass innerClass = new InnerClass();

        OutClass.InnerClass innerClass = new OutClass.InnerClass();
        innerClass.test();


    }
}

